var Tank = Window02.extend({
	ctor:function (parent, flow, tag) {
		this._super(parent, flow, tag);
	},
	initSp:function (){
		// 定位针
		var pin =  new Button(this.rootNode,
				d_z_index, TAG_TANK_PIN,
				"#tank/pin.png",
				this.eventMenuCallback,this);
		pin.setPosition(800,300);
		var y1 = 180, y2 = 320;
		// 底垫
		var didian = new Button(this.rootNode, 
				d_z_index, TAG_TANK_DIDIAN,
				"#tank/didian.png",
				this.eventMenuCallback,this);
		didian.setPosition(400,y1);
		// 顶垫
		var dingdian = new Button(this.rootNode, 
				d_z_index, TAG_TANK_DINGDIAN,
				"#tank/dingdian.png",
				this.eventMenuCallback,this);
		dingdian.setPosition(500,y1);
		// 密封盖(标准罐)
		var mifenggai1 = new Button(this.rootNode, 
				d_z_index, TAG_TANK_MIFENGGAI1,
				"#tank/mifenggai1.png",
				this.eventMenuCallback,this);
		mifenggai1.setPosition(700,y2);
		// 密封盖(控制罐)
		var mifenggai2 = new Button(this.rootNode, 
				d_z_index, TAG_TANK_MIFENGGAI2,
				"#tank/mifenggai2.png",
				this.eventMenuCallback,this);
		mifenggai2.setPosition(700,y1);
		// 放气螺钉
		var luoding = new Button(this.rootNode,
				d_z_index, TAG_TANK_LUODING,
				"#tank/luoding.png",
				this.eventMenuCallback,this);
		luoding.setPosition(725, 312);
		// 顶丝
		var dingsi = new Button(this.rootNode,
				d_z_index, TAG_TANK_DINGSI,
				"#tank/dingsi.png",
				this.eventMenuCallback,this);
		dingsi.setPosition(600,y1);
		// 框架
		var kuangjia = new Button(this.rootNode,
				d_z_index, TAG_TANK_KUANGJIA,
				"#tank/kuangjia.png",
				this.eventMenuCallback,this);
		kuangjia.setPosition(240,y2);
		// 溶样杯
		var rongyangbei = new Button(this.rootNode,
				d_z_index, TAG_TANK_RONGYANGBEI,
				"#tank/rongyangbei.png",
				this.eventMenuCallback,this);
		rongyangbei.setPosition(400,y2);
		// 扩口器
		var kuokou =  new Button(this.rootNode,
				d_z_index, TAG_TANK_KUOKOU,
				"#tank/kuokou.png",
				this.eventMenuCallback,this);
		kuokou.setPosition(600,y2);
		// 套筒
		var taotong = new Button(this.rootNode,
				d_z_index, TAG_TANK_TAOTONG,
				"#tank/taotong.png",
				this.eventMenuCallback,this);
		taotong.setPosition(500,y2);
		// 溶样杯架
		var beijia = new Button(this.rootNode,
				d_z_index, TAG_TANK_BEIJIA,
				"#tank/beijia1.png",
				this.eventMenuCallback,this);
		beijia.setPosition(500,470);
		// tank里的扳手
		var banshou2 = new Button(this.rootNode,
				d_z_index, TAG_TANK_BANSHOU2,
				"#other/banshou.png",
				this.eventMenuCallback,this);
		banshou2.setPosition(300,400);
		banshou2.setVisible(false);
		
		var ban4 = new Button(this.rootNode,
				d_z_index, TAG_BANSHOU4,
				"#other/banshou4.png",
				this.eventMenuCallback,this);
		ban4.setPosition(297,400);
		ban4.setVisible(false);
		var ban5 = new Button(this.rootNode,
				d_z_index, TAG_BANSHOU5,
				"#other/banshou5.png",
				this.eventMenuCallback,this);
		ban5.setPosition(272,396);
		ban5.setRotation(21);
		ban5.setVisible(false);

	},
	callbackSp:function (pSender){
		cc.log("say:" + pSender.getTag());
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.checkActionDone, this);
		switch (pSender.getTag()){
		case TAG_TANK_RONGYANGBEI:
			if(action == ACTION_NONE){
				// 检查溶样杯
				gg.flow.next();
			} else if(action == ACTION_DO1){
				// 将消解罐内罐放置预溶样杯架上
				pSender.move(func, cc.p(470,455), 0.3);
			} else if(action == ACTION_DO2){
				// 放入套筒
				pSender.move(func, cc.p(500,320), 0.5);
			} else if(action == ACTION_DO3){
				// 打卡密封盖
				pSender.setSpriteFrame("tank/rongyangbei.png");
				var mifenggai = this.byTag(TAG_TANK_MIFENGGAI2);
				mifenggai.setVisible(true);
				var move = cc.moveTo(0.5, mifenggai.getPosition());
				mifenggai.runAction(move);
				gg.flow.next();
			} else if(action == ACTION_DO4){
				// 放入DKQ TODO
				var move1 = cc.moveTo(0.5,cc.p(90,305));
				var scale1 = cc.scaleTo(0.5, 0.2);
				var spawn = cc.spawn(move1, scale1);
				var seq = cc.sequence(spawn,func);
				pSender.runAction(seq);
			}
			break;
		case TAG_TANK_LUODING:
			gg.flow.next();
			if(action == ACTION_DO1){
				pSender.setVisible(false);
				var bei_stand = this.byTag(TAG_TANK_MIFENGGAI1);
				bei_stand.setSpriteFrame("tank/mifenggai3.png");
			}
			break;
		case TAG_TANK_MIFENGGAI2:
			if(action == ACTION_NONE){
				gg.flow.next();	
			} else if(action == ACTION_DO1){
				var rotate = cc.rotateTo(0.6, 180);
				var move1 = cc.moveTo(0.6,cc.p(400, 450));
				var move2 = cc.moveTo(0.4,cc.p(400, 340));
				pSender.setVisible(true);
				var seq = cc.sequence(rotate, move1, move2, func);
				pSender.runAction(seq);
			} else if(action == ACTION_DO2){
				pSender.setVisible(false);
				var bei = this.byTag(TAG_TANK_RONGYANGBEI);
				bei.setSpriteFrame("tank/rongyangbei2.png");
				gg.flow.next();
			}
			break;
		case TAG_TANK_BEIJIA:
			if(action == ACTION_DO1){
				pSender.setSpriteFrame("tank/beijia_l2.png");
				pSender.move(func, cc.p(90, 295), 0.8);
			} else if(action == ACTION_DO5){
				pSender.setSpriteFrame("tank/beijia_l1.png");
				pSender.setVisible(false);
				var bei = this.byTag(TAG_TANK_RONGYANGBEI);
				bei.setPosition(90, 295);
				bei.move(func, cc.p(400,320), 0.8);
			}
			break;
		case TAG_TANK_KUOKOU:
			if(action == ACTION_DO1){
				var rotate = cc.rotateTo(0.8, 180);
				var move1 = cc.moveTo(0.8,cc.p(700,225));
				var move2 = cc.moveTo(0.4,cc.p(700,170));
				pSender.setVisible(true);
				var seq = cc.sequence(rotate, move1, move2, func);
				pSender.runAction(seq);
			} else if(action == ACTION_DO2){
				gg.flow.next();
			} else if(action == ACTION_DO3){
				var rotate = cc.rotateTo(0.8, 0);
				pSender.move2(func, cc.p(600,320), rotate, 0.8);
			}
			break;
		case TAG_TANK_MIFENGGAI1:
			if(action == ACTION_DO1){
				var rotate = cc.rotateTo(0.8, 180);
				pSender.move3(func, cc.p(400,400), rotate, 0.8);
			} else if(action == ACTION_DO2){
				pSender.setVisible(false);
				var bei = this.byTag(TAG_TANK_RONGYANGBEI);
				bei.setSpriteFrame("tank/rongyangbei2.png");
				gg.flow.next();
			}
			break;
		case TAG_TANK_DINGDIAN:
			pSender.move(func, cc.p(500,380), 0.5);
			break;
		case TAG_TANK_DIDIAN:
			pSender.move(func, cc.p(255,250), 0.5);
			break;
		case TAG_TANK_DINGSI:
			pSender.move(func, cc.p(240,400), 0.6);
			break;
		case TAG_TANK_TAOTONG:
			if(action == ACTION_DO1){
				// 套筒放入框架
				pSender.move(func, cc.p(255,320), 0.6);
			} else if(action == ACTION_DO3){
				// 套筒取出溶样杯
				var rongyangbei = this.byTag(TAG_TANK_RONGYANGBEI);
				rongyangbei.move(func, cc.p(400,320), 0.6);
				pSender.setSpriteFrame("tank/taotong.png");
			}
			break;
		case TAG_TANK_PIN:
			var move = cc.moveTo(0.6, cc.p(240,370));
			pSender.move2(func, cc.p(240,420), move, 0.6);
			break;
		case TAG_TANK_KUANGJIA:
			var taotong = this.byTag(TAG_TANK_TAOTONG);
			taotong.move(func, cc.p(500,320), 0.6);
			pSender.setSpriteFrame("tank/kuangjia3.png");
			break;
		case TAG_BANSHOU4:				
				var ban5= this.byTag(TAG_BANSHOU5);
				var ban4= this.byTag(TAG_BANSHOU4);
				var fadeout=cc.fadeOut(0);
				var fadein=cc.fadeIn(0);
				var del=cc.delayTime(0.2);
				var seq1=cc.sequence(fadeout,cc.callFunc(function() {
					ban5.setVisible(true);
				}, this),del,cc.callFunc(function() {
					ban5.setVisible(false);
				}, this),fadein,del,fadeout,cc.callFunc(function() {
					ban5.setVisible(true);
				}, this),del,cc.callFunc(function() {
					ban5.setVisible(false);				
				}, this),fadein,del,fadeout);
				var seq2=cc.sequence(cc.repeat(seq1,2),cc.callFunc(function() {
					_.ka();
				}, this),func);
				pSender.runAction(seq2);
				ll.run.pinTank();
			break;
		default:
			break;
		}
	},
	checkActionDone:function (pSender){
		var layer = pSender.getParent().getParent().getParent();
		var tank = this.layer.tank;
		var action = gg.flow.flow.action;
		if(pSender.getTag() == TAG_TANK_RONGYANGBEI){
			if(action == ACTION_DO1){
				// 溶样杯放入杯架
				var beijia = tank.byTag(TAG_TANK_BEIJIA);
					beijia.setSpriteFrame("tank/beijia2.png");
					pSender.setVisible(false);
					tank.rootNode.scheduleOnce(tank.close.bind(this),0.5);	
					this.step=1;
			} else if(action == ACTION_DO2){
				// 溶样杯放入套筒
				pSender.setVisible(false);
				var taotong = tank.byTag(TAG_TANK_TAOTONG);
				taotong.setSpriteFrame("tank/finish1.png");
			} else if(action == ACTION_DO4){
				pSender.setVisible(false);
			}
		} else if(pSender.getTag() == TAG_TANK_BEIJIA){
			pSender.removeFromParent(true);
			ll.run.addChild(pSender, TAG_TANK_BEIJIA);
			pSender.addListener(); // 重新添加监听
		} else if(pSender.getTag() == TAG_TANK_DINGDIAN){
			pSender.setVisible(false);
			var taotong = tank.byTag(TAG_TANK_TAOTONG);
			taotong.setSpriteFrame("tank/finish2.png");
		} else if(pSender.getTag() == TAG_TANK_TAOTONG){
			var kuangjia = this.byTag(TAG_TANK_KUANGJIA);
			if(action == ACTION_DO1){
				// 套筒放入框架
				pSender.setVisible(false);
				kuangjia.setSpriteFrame("tank/kuangjia4.png");		
			}
		} else if(pSender.getTag() == TAG_TANK_DINGSI){
			// 顶丝
			pSender.setVisible(false);
			var kuangjia = tank.byTag(TAG_TANK_KUANGJIA);
			kuangjia.setSpriteFrame("tank/kuangjia3.png");
		} else if(pSender.getTag() == TAG_TANK_DIDIAN){
			// 底垫
			pSender.setVisible(false);
			var kuangjia = tank.byTag(TAG_TANK_KUANGJIA);
			kuangjia.setSpriteFrame("tank/kuangjia2.png");
		} else if(pSender.getTag() == TAG_TANK_PIN){
			pSender.setVisible(false);
			var kuangjia = tank.byTag(TAG_TANK_KUANGJIA);
			kuangjia.setSpriteFrame("tank/kuangjia5.png");
		}else if(pSender.getTag() == TAG_TANK_BANSHOU){
			if(action == ACTION_DO2){
				pSender.setSpriteFrame("other/banshou_item.png");
			}
		}else if(pSender.getTag() == TAG_BANSHOU4){
			var mov=cc.moveTo(0.6, cc.p(795,632));
			var seq=cc.sequence(mov,cc.callFunc(function() {
				pSender.setVisible(false);
			}, this));
			pSender.runAction(seq);
			
			var banshou1=this.layer.getChildByTag(TAG_TANK_BANSHOU);	
			var totate = cc.rotateTo(0.6, 0);
			var move=cc.moveTo(0.6, cc.p(795,632));
			var spa=cc.spawn(totate,move);
			var seq=cc.sequence(spa,cc.callFunc(function() {
				banshou1.setVisible(true);
				banshou1.setSpriteFrame("other/banshou_item.png");
			}, this));
			banshou1.runAction(seq);
		}
		gg.flow.next();
		this.destroy();
	},
	hidden:function(){
		this.setVisible(false);
	}
})